/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

import { Json5Reader } from '@ohos/hvigor';
import * as fse from 'fs-extra';

/**
 * 配置文件修改的基类
 */
export class BaseModifier {
  protected jsonObject: any;
  protected jsonUrl: string;

  constructor(src: string) {
    this.jsonObject = Json5Reader.getJson5Obj(src);
    this.jsonUrl = src;
  }

  public getObject() {
    return this.jsonObject;
  }

  public outputSync() {
    fse.outputJSONSync(this.jsonUrl, this.jsonObject);
  }

  public async output() {
    await fse.outputJSON(this.jsonUrl, this.jsonObject);
  }
}
